package org.rsbot.loader.script.adapter;

import org.rsbot.loader.asm.AnnotationVisitor;
import org.rsbot.loader.asm.Attribute;
import org.rsbot.loader.asm.ClassAdapter;
import org.rsbot.loader.asm.ClassVisitor;
import org.rsbot.loader.asm.FieldVisitor;
import org.rsbot.loader.asm.Label;
import org.rsbot.loader.asm.MethodVisitor;

public class OverrideJavaClassAdapter extends ClassAdapter
{
  private String old_clazz;
  private String new_clazz;

  public OverrideJavaClassAdapter(ClassVisitor paramClassVisitor, String paramString1, String paramString2)
  {
    super(paramClassVisitor);
    this.old_clazz = paramString1;
    this.new_clazz = paramString2;
  }

  public MethodVisitor visitMethod(int paramInt, String paramString1, String paramString2, String paramString3, String[] paramArrayOfString)
  {
    return new MethodAdapter(this.cv.visitMethod(paramInt, paramString1, paramString2, paramString3, paramArrayOfString), this.old_clazz, this.new_clazz);
  }

  public FieldVisitor visitField(int paramInt, String paramString1, String paramString2, String paramString3, Object paramObject) {
    if (paramString2.equals("L" + this.old_clazz + ";")) {
      paramString2 = "L" + this.new_clazz + ";";
    }
    return this.cv.visitField(paramInt, paramString1, paramString2, paramString3, paramObject);
  }

  static class MethodAdapter implements MethodVisitor
  {
    private MethodVisitor mv;
    private String old_clazz;
    private String new_clazz;

    MethodAdapter(MethodVisitor paramMethodVisitor, String paramString1, String paramString2) {
      this.mv = paramMethodVisitor;
      this.old_clazz = paramString1;
      this.new_clazz = paramString2;
    }

    public AnnotationVisitor visitAnnotationDefault() {
      return this.mv.visitAnnotationDefault();
    }

    public AnnotationVisitor visitAnnotation(String paramString, boolean paramBoolean) {
      return this.mv.visitAnnotation(paramString, paramBoolean);
    }

    public AnnotationVisitor visitParameterAnnotation(int paramInt, String paramString, boolean paramBoolean) {
      return this.mv.visitParameterAnnotation(paramInt, paramString, paramBoolean);
    }

    public void visitAttribute(Attribute paramAttribute) {
      this.mv.visitAttribute(paramAttribute);
    }

    public void visitCode() {
      this.mv.visitCode();
    }

    public void visitFrame(int paramInt1, int paramInt2, Object[] paramArrayOfObject1, int paramInt3, Object[] paramArrayOfObject2)
    {
    }

    public void visitInsn(int paramInt) {
      this.mv.visitInsn(paramInt);
    }

    public void visitIntInsn(int paramInt1, int paramInt2) {
      this.mv.visitIntInsn(paramInt1, paramInt2);
    }

    public void visitVarInsn(int paramInt1, int paramInt2) {
      this.mv.visitVarInsn(paramInt1, paramInt2);
    }

    public void visitTypeInsn(int paramInt, String paramString) {
      if (paramString.equals(this.old_clazz)) {
        paramString = this.new_clazz;
      }
      this.mv.visitTypeInsn(paramInt, paramString);
    }

    public void visitFieldInsn(int paramInt, String paramString1, String paramString2, String paramString3) {
      if (paramString3.contains(this.old_clazz)) {
        paramString3 = paramString3.replace("L" + this.old_clazz + ";", "L" + this.new_clazz + ";");
      }
      this.mv.visitFieldInsn(paramInt, paramString1, paramString2, paramString3);
    }

    public void visitMethodInsn(int paramInt, String paramString1, String paramString2, String paramString3) {
      if (paramString1.equals(this.old_clazz)) {
        paramString1 = this.new_clazz;
        paramString3 = paramString3.replace("L" + this.old_clazz + ";", "L" + this.new_clazz + ";");
      }

      this.mv.visitMethodInsn(paramInt, paramString1, paramString2, paramString3);
    }

    public void visitJumpInsn(int paramInt, Label paramLabel) {
      this.mv.visitJumpInsn(paramInt, paramLabel);
    }

    public void visitLabel(Label paramLabel) {
      this.mv.visitLabel(paramLabel);
    }

    public void visitLdcInsn(Object paramObject) {
      this.mv.visitLdcInsn(paramObject);
    }

    public void visitIincInsn(int paramInt1, int paramInt2) {
      this.mv.visitIincInsn(paramInt1, paramInt2);
    }

    public void visitTableSwitchInsn(int paramInt1, int paramInt2, Label paramLabel, Label[] paramArrayOfLabel) {
      this.mv.visitTableSwitchInsn(paramInt1, paramInt2, paramLabel, paramArrayOfLabel);
    }

    public void visitLookupSwitchInsn(Label paramLabel, int[] paramArrayOfInt, Label[] paramArrayOfLabel) {
      this.mv.visitLookupSwitchInsn(paramLabel, paramArrayOfInt, paramArrayOfLabel);
    }

    public void visitMultiANewArrayInsn(String paramString, int paramInt) {
      this.mv.visitMultiANewArrayInsn(paramString, paramInt);
    }

    public void visitTryCatchBlock(Label paramLabel1, Label paramLabel2, Label paramLabel3, String paramString) {
      this.mv.visitTryCatchBlock(paramLabel1, paramLabel2, paramLabel3, paramString);
    }

    public void visitLocalVariable(String paramString1, String paramString2, String paramString3, Label paramLabel1, Label paramLabel2, int paramInt) {
      this.mv.visitLocalVariable(paramString1, paramString2, paramString3, paramLabel1, paramLabel2, paramInt);
    }

    public void visitLineNumber(int paramInt, Label paramLabel)
    {
    }

    public void visitMaxs(int paramInt1, int paramInt2) {
      this.mv.visitMaxs(paramInt1, paramInt2);
    }

    public void visitEnd() {
      this.mv.visitEnd();
    }
  }
}